#pragma once

struct SDL_Thread;
struct SDL_cond;
struct SDL_mutex;

namespace EThread
{
	enum Type
	{
		Synchronize,
		SynchronizeBeforeRendering,
		Asynchronous
	};
}

class IThread
{
public:
	IThread(const std::string& name, float frequency, EThread::Type type);
	virtual ~IThread();

	void				StartThread();
	void				StopThread();
	void				Wait(int* returnValue);

	int					ThreadFunc();
	virtual void		OnThreadStart();
	virtual void		OnThreadStop();

	const std::string&	GetThreadName() const;
	float				GetFrequency() const;
	EThread::Type		GetSyncType() const;

	void				LockCond();
	void				UnlockCond();
	void				LockMutex();
	void				UnlockMutex();

protected:
	virtual int			ThreadLoop() = 0;
	
	float				m_frequency;
	bool				m_keepThreadAlive;

	SDL_Thread*			m_sdlthread;
	SDL_mutex*			m_mutex;
	SDL_cond*			m_cond;

	const std::string	m_name;
	EThread::Type		m_synctype;
};

int ThreadFunction(void* data);
